<%@ include file="inc/taglibs.jsp" %>
<%@ tag import="java.io.StringReader,java.io.BufferedReader" %>

<%@ attribute name="render" type="java.lang.String" required="true" description="(TYPE:string DESC:Id of dialog render.)" %>
<%@ attribute name="width" type="java.lang.Integer" required="false" description="(TYPE:int DESC:)" %>
<%@ attribute name="height" type="java.lang.Integer" required="false" description="(TYPE:int DESC:)" %>
<%@ attribute name="cssClass" type="java.lang.String" required="false" description="(TYPE:int DESC:)" %>

<jsp:doBody var="pageHTML" />
<%
	String pageHTML = (String)jspContext.getAttribute("pageHTML");
	String stripPageHtml = "";
	String pageLine = "";
	
	BufferedReader br = new BufferedReader(new StringReader(pageHTML));
    while((pageLine=br.readLine())!=null) {
        if (pageLine.trim().length()>0) stripPageHtml+=pageLine+"\n";
    }
	
	jspContext.setAttribute("pageHTML",stripPageHtml);
	

	if(width == null || width <= 0){
		jspContext.setAttribute("width", 400);
	}

	if(height == null || height <= 0){
		jspContext.setAttribute("height", 200);
	}
	
	if(cssClass == null || cssClass.isEmpty()){
		jspContext.setAttribute("cssClass", "");
	}
%>
<script src="<c:url value="/scripts/ckeditor/ckeditor.js" />" type="text/javascript"></script>
<script src="<c:url value="/scripts/ckeditor/adapters/jquery.js" />" type="text/javascript"></script>
<textarea id="${render}" name="${render}" style="width:${width};height:${height};" class="${cssClass}">${pageHTML}</textarea>

<script type="text/javascript">
//<![CDATA[
$(function()
{
	var config = {
		toolbar:
		[  
			['Copy','Cut','Paste'],
		    ['Bold','Italic'],     
		    ['JustifyLeft','JustifyCenter','JustifyRight','JustifyBlock'], 
		    ['Styles','Font','FontSize'],
		    ['Image','Table','HorizontalRule','SpecialChar','PageBreak'],     
		    ['TextColor'],     
		    ['Undo','Redo']
		],
		language:'zh-cn',
		width:'${width}',
		height:'${height}'
	};

	$('#${render}').ckeditor(config);
});

//]]>
</script>